import { HttpException, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { PostsEntity } from './posts.entity';

@Injectable()
export class PostsService {
  constructor(
    @InjectRepository(PostsEntity)
    private readonly postsRepository: Repository<PostsEntity>,
  ) {}
  postTest(): string {
    return 'postTest';
  }
  async create(post: Partial<PostsEntity>): Promise<PostsEntity> {
    console.log('lgh: ', post);
    const { title } = post;
    if (!title) {
      throw new HttpException('缺失文章标题', 401);
    }
    return await this.postsRepository.save(post);
  }
}
